<?php

namespace App\Http\Controllers\Api;

use Auth;
use App\Models\Response;

class AuthorizationController extends Controller
{
    public function login() {
        $credentials = request(['email','password']);
        $token = auth('api')->attempt($credentials,true);
        $response = new Response();
        if(!$token) {
            $response->setCode(201);
            return json_encode($response);
        }else{
            $response->setCode(200);
            $data = [
                'token' => $token,
                'user' => auth('api')->user()
            ];
            $response->setData($data);
            return json_encode($response);
        }
    }
}
